package com.cloud.pole.pay.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.cloud.pole.api.param.PicklistApi;
import com.cloud.pole.common.constant.CommonConstants;
import com.cloud.pole.common.exception.BaseException;
import com.cloud.pole.common.exception.ParamException;
import com.cloud.pole.common.msg.ApiRestResponse;
import com.cloud.pole.common.rest.BaseController;
import com.cloud.pole.common.util.RegexUtils;
import com.cloud.pole.pay.biz.PayCcbBiz;
import com.cloud.pole.pay.service.PayCcbService;

import lombok.extern.slf4j.Slf4j;

@Controller
@RequestMapping("payCcb/front")
@Slf4j
public class PayCcbController{

	@Autowired
	private PayCcbService payCcbService;
	
	@ResponseBody
    @RequestMapping(value = "testPayCcb",method = RequestMethod.GET)
    public ApiRestResponse<Map<String, Object>> testPayCcb(
    		@RequestParam(defaultValue = "") String payId,
    		@RequestParam(defaultValue = "") String amount,
    		@RequestParam(defaultValue = "") String orderId){   	
    	try {
			ParamException.err(StringUtils.isBlank(payId), "支付ID不能为空");    		
			ParamException.err(!RegexUtils.isPositiveInteger(payId), "支付ID类型错误");    		
			ParamException.err(StringUtils.isBlank(orderId), "订单号不能为空");    		
			ParamException.err(StringUtils.isBlank(amount), "金额不能为空");    		
			ParamException.err(!RegexUtils.isPositiveInteger(amount), "金额类型错误");    		
			return ApiRestResponse.success(CommonConstants.STATUS_OK_MESSAGE, payCcbService.threeStarPayInApp(Integer.parseInt(payId), orderId, Long.parseLong(amount)));
    	} catch (BaseException e) {
			return ApiRestResponse.fail(e.getStatus(), e.getMessage(), null);
		} catch (Exception e) {
			log.error(CommonConstants.STATUS_ERROR_MESSAGE + "{}", e.getMessage(), e);
			return ApiRestResponse.fail(CommonConstants.STATUS_ERROR_MESSAGE, null);
		}
    }
}
